package analyzer.pcap;

import analyzer.Common;

import java.io.FileInputStream;
import java.io.IOException;
/**
 * Timestamp 4B integer part
 * Timestamp 4B decimal part
 * Capture length 4B
 * Length 4B
 */
public class PacketHeader {

    public static void analyze(FileInputStream in)
    {
        timestampHigh(in);
        capLen(in);
        len(in);
    }
    private static void timestampHigh(FileInputStream in){
        byte[] b = new byte[4];
        byte[] b1 = new byte[4];
        try {
            in.read(b);
            in.read(b1);
            int integerPart = Common.convertToInt(b);
            int decimalPart =  Common.convertToInt(b1);
            System.out.println("time is " + integerPart + "." + decimalPart);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private static void capLen(FileInputStream in)
    {
        byte[] b = new byte[4];
        try {
            in.read(b);
            int length =  Common.convertToInt(b);
            System.out.println("capture length is " + length);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private static void len(FileInputStream in)
    {
        byte[] b = new byte[4];
        try {
            in.read(b);
            int length =  Common.convertToInt(b);
            System.out.println("packet length is " + length);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
